home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_tkcvs.idb / usr / freeware / lib / tkcvs / cvs.tcl.z / cvs.tcl
Encoding:
Text File  |  1999-04-16  |  21.8 KB  |  898 lines

  1. #
  2. # TCL Library for tkCVS
  3. #
  4.  
  5. #
  6. # $Id: cvs.tcl,v 1.41 1996/05/25 02:54:58 del Exp $
  7. # Contains procedures used in interaction with CVS.
  8. #
  9.  
  10. proc cvs_notincvs {} {
  11.   cvserror "This directory is not in CVS.\nPlease import it first."
  12. }
  13.  
  14. proc cvs_incvs {} {
  15.   cvserror "You cant do that here because this directory is already in CVS."
  16. }
  17.  
  18. proc cvs_remote_bad {} {
  19.   cvserror "You cant do that with a remote CVS repository."
  20. }
  21.  
  22. proc cvs_remove args {
  23. #
  24. # This deletes a file from the directory and the repository,
  25. # asking for confirmation first.
  26. #
  27.   global cvs
  28.   global incvs
  29.   # need access to cvscfg(rm_cmd) and cvscfg(rm_flags) 
  30.   # -sj
  31.   global cvscfg
  32.  
  33.   if {$args == "{}"} {
  34.     cvserror "Please select some files to delete first!"
  35.     return
  36.   }
  37.  
  38.   # modified to provide a more detailed warning  
  39.   # and use the cvscfg(rm_cmd) and cvscfg(rm_flags) 
  40.   # -sj
  41.   set mess ""
  42.   if {$incvs} {
  43.     set mess "WARNING!!! This will modify"
  44.     set mess "$mess the contents of the CVS"
  45.     set mess "$mess repository!!!!"
  46.   }
  47.   set mess "$mess\n\nYou are about to remove these"
  48.   set mess "$mess files:"
  49.   if { [ are_you_sure $mess $args ] == 1 } {
  50.     set results ""
  51.     foreach file $args {
  52.       eval exec $cvscfg(rm_cmd) $cvscfg(rm_flags) $file
  53.       if {$incvs} {
  54.         catch {eval "exec $cvs remove $file"} view_this
  55.         if { $view_this != "" } {set results "$results\n$view_this" }
  56.       }
  57.     }
  58.     view_output "CVS Delete" $results
  59.     setup_dir
  60.   }
  61. }
  62.  
  63. proc cvs_add args {
  64. #
  65. # This adds a file to the repository.
  66. #
  67.   global cvs
  68.   global incvs
  69.  
  70.   if {! $incvs} {
  71.     cvs_notincvs
  72.     return 1
  73.   }
  74.  
  75.   if {$args == "{}"} {
  76.     set mess "This will add all new files!"
  77.   } else {
  78.     set mess "This will add these files:\n\n"
  79.     foreach file $args {
  80.       set mess "$mess   $file\n"
  81.     }  
  82.   }
  83.  
  84.   set mess "$mess\nAre you sure?"
  85.   set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  86.  
  87.   if {$confirm == 0} {
  88.     if {$args == "{}"} {
  89.       foreach file [glob -nocomplain *] {
  90.         catch {eval "exec $cvs add $file"} view_this
  91.         # Probably don't need to see the output, but you can uncomment this
  92.         # line if you like.
  93.         # view_output "CVS Add" $view_this
  94.       }
  95.     } else {
  96.       foreach file $args {
  97.         catch {eval "exec $cvs add $file"} view_this
  98.         # view_output "CVS Add" $view_this
  99.       }
  100.     }
  101.   }
  102. }
  103.  
  104. proc cvs_diff args {
  105. #
  106. # This diffs a file with the repository.
  107. #
  108.   global cvs
  109.   global incvs
  110.  
  111.   if {! $incvs} {
  112.     cvs_notincvs
  113.     return 1
  114.   }
  115.  
  116.   if {$args == "{}"} {
  117.     foreach file [glob -nocomplain *] {
  118.       catch {eval "exec tkdiff -C $file &"} view_this
  119.     }
  120.   } else {
  121.     foreach file $args {
  122.       catch {eval "exec tkdiff -C $file &"} view_this
  123.     }
  124.   }
  125. }
  126.  
  127. proc cvs_diff_r {rev1 rev2 args} {
  128. #
  129. # This diffs a file with the repository, using two revisions or tags.
  130. #
  131.   global cvs
  132.   global incvs
  133.  
  134.   if {! $incvs} {
  135.     cvs_notincvs
  136.     return 1
  137.   }
  138.   if {$rev1 == {} || $rev2 == {}} {
  139.     cvserror "Must have two revision numbers for this function!"
  140.     return 1
  141.   }
  142.  
  143.   if {$args == "{}"} {
  144.     foreach file [glob -nocomplain *] {
  145.       catch {eval "exec tkdiff -C $rev1 -C $rev2 $file &"} view_this
  146.     }
  147.   } else {
  148.     foreach file $args {
  149.       catch {eval "exec tkdiff -C $rev1 -C $rev2 $file &"} view_this
  150.     }
  151.   }
  152. }
  153.  
  154. proc cvs_view_r {rev args} {
  155. #
  156. # This views a specific revision of a file in the repository.
  157. #
  158.   global cvs
  159.   global incvs
  160.  
  161.   if {! $incvs} {
  162.     cvs_notincvs
  163.     return 1
  164.   }
  165.  
  166.   if {$args == "{}"} {
  167.     foreach file [glob -nocomplain *] {
  168.       catch {eval "exec $cvs update -p -r $rev $file 2>/dev/null"} view_this
  169.       view_output "CVS View" $view_this
  170.     }
  171.   } else {
  172.     foreach file $args {
  173.       catch {eval "exec $cvs update -p -r $rev $file 2>/dev/null"} view_this
  174.       view_output "CVS View" $view_this
  175.     }
  176.   }
  177. }
  178.  
  179. proc cvs_logcanvas args {
  180. #
  181. # This looks at a log from the repository.
  182. #
  183.   global cvs
  184.   global incvs
  185.  
  186.   if {! $incvs} {
  187.     cvs_notincvs
  188.     return 1
  189.   }
  190.  
  191.   if {$args == "{}"} {
  192.     set filelist "."
  193.   } else {
  194.     set filelist $args
  195.   }
  196.   foreach file $filelist {
  197.     catch {eval "exec $cvs log $file"} view_this
  198.     # New style file log viewer
  199.     new_logcanvas $file $view_this
  200.   }
  201. }
  202.  
  203. proc cvs_log args {
  204. #
  205. # This looks at a log from the repository.
  206. # This is an old style file log with just the output from cvs log.
  207. #
  208.   global cvs
  209.   global incvs
  210.   # need access to cvscfg (ldetail)
  211.   # -sj
  212.   global cvscfg
  213.  
  214.   if {! $incvs} {
  215.     cvs_notincvs
  216.     return 1
  217.   }
  218.  
  219.   if {$args == "{}"} {
  220.     set filelist "."
  221.   } else {
  222.     set filelist $args
  223.   }
  224.   # modified to allow for varying level of detail
  225.   # -sj
  226.   if {$cvscfg(cvsver) < 1.3} {
  227.     set cvscfg(ldetail) "verbose"
  228.   }
  229.  
  230.   if { $cvscfg(ldetail) == "verbose" } {
  231.     set commandline "exec $cvs log $filelist"
  232.   } elseif { $cvscfg(ldetail) == "last" || $cvscfg(ldetail) == "summary"} {
  233.     set commandline "exec cvs -l -n log -l $filelist "
  234.     set commandline "$commandline | awk { BEGIN {LM=-1000}\n"
  235.     set commandline "$commandline \$0 ~ /----------------------------/"
  236.     set commandline "$commandline {LM=0; printf(\"\\n--------------------\\n\");}"
  237.     set commandline "$commandline \$0 ~ /\\=\\=\\=\\=\\=\\=\\=\\=\\=\\=\\=\\=\\=\\="
  238.     set commandline "$commandline\\=\\=\\=\\=\\=\\=\\=\\=\\=\\=\\=\\=\\=\\=/ "
  239.     set commandline "$commandline {LM=0; printf(\"\\n\");}"
  240.     set commandline "$commandline {if (LM \=\= 1) printf(\"%s \", \$0);"
  241.     set commandline "$commandline if (LM \>\= 3) printf(\"%s \", \$0);"
  242.     set commandline "$commandline LM\+\+;}} "
  243.     set commandline "$commandline | tail \+2"
  244.     if {$cvscfg(ldetail) == "last" } {
  245.       set commandline "$commandline | head \-2 "
  246.     }
  247.   }
  248.  
  249.   # puts stderr "command line is $commandline"
  250.   catch { eval $commandline } view_this
  251.   view_output "CVS Log" $view_this
  252. }
  253.  
  254. proc cvs_commit {revision comment args} {
  255. #
  256. # This commits changes to the repository.
  257. #
  258. # The parameters work differently here -- args is a list.  The first
  259. # element of args is a list of file names.  This is because I can't
  260. # use eval on the parameters, because comment contains spaces.
  261. #
  262.   global cvs
  263.   global cvscfg
  264.   global incvs
  265.   global filelist
  266.  
  267.   # puts stderr "Revision = $revision"
  268.   # puts stderr "Comment  = $comment"
  269.  
  270.   if {! $incvs} {
  271.     cvs_notincvs
  272.     return 1
  273.   }
  274.  
  275.   if {$comment == ""} {
  276.     cvserror "You must enter a comment!"
  277.     return 1
  278.   }
  279.  
  280.   if {$args == "{}"} {
  281.     set filelist "."
  282.     if {$cvscfg(cvsver) < 1.3} {
  283.       # cosmetic cleanup
  284.       # -sj
  285.       set errstr "You must select files to be committed with CVS version"
  286.       set errstr "$errstr $cvscfg(cvsver)."
  287.       set errstr "$errstr\n\nEither select a list of files or upgrade
  288.       set errstr "$errstr your CVS to version 1.3"
  289.       cvserror "$errstr"
  290.       return
  291.     }
  292.   } else {
  293.     set filelist [lindex $args 0]
  294.   }
  295.  
  296.   # changed the message to be a little more explicit.
  297.   # -sj
  298.   set commit_output ""
  299.   if { $filelist == "." } {
  300.       set mess "This will commit your changes to ** ALL ** files in"
  301.       set mess "$mess and under this directory.\n\nAre you sure?"
  302.   } else {
  303.       foreach file $filelist {
  304.       set commit_output "$commit_output\n$file"
  305.       }
  306.       set mess "This will commit your changes to:$commit_output\n\nAre you sure?"
  307.   }
  308.   set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  309.  
  310.   set commit_output ""
  311.   if {$confirm == 0} {
  312.     if {$revision != ""} {
  313.       if {$cvscfg(cvsver) < 1.3} {
  314.         foreach file $filelist {
  315.           # puts stderr "1 Committing $file"
  316.           catch {exec $cvs commit -f -r $revision -m "$comment" $file} \
  317.             commit_tmp
  318.           set commit_output "$commit_output\n$commit_tmp"
  319.         }
  320.       } else {
  321.         foreach file $filelist {
  322.           # puts stderr "2 Committing $file"
  323.           catch {exec $cvs commit -r $revision -m "$comment" $file} \
  324.             commit_tmp
  325.           set commit_output "$commit_output\n$commit_tmp"
  326.         }
  327.       }
  328.     } else {
  329.       if {$cvscfg(cvsver) < 1.3} {
  330.         foreach file $filelist {
  331.           # puts stderr "3 Committing $file"
  332.           catch {exec $cvs commit -f -m "$comment" $file} \
  333.             commit_tmp
  334.           set commit_output "$commit_output\n$commit_tmp"
  335.         }
  336.       } else {
  337.         foreach file $filelist {
  338.           # puts stderr "4 Committing $file"
  339.           catch {exec $cvs commit -m "$comment" $file} \
  340.             commit_tmp
  341.           set commit_output "$commit_output\n$commit_tmp"
  342.         }
  343.       }
  344.     }
  345.     view_output "CVS Commit" $commit_output
  346.   }
  347. }
  348.  
  349. proc cvs_tag {tagname branch args} {
  350. #
  351. # This tags a file in a directory.
  352. #
  353.   global cvs
  354.   global cvscfg
  355.   global incvs
  356.   global filelist
  357.  
  358.   if {$cvscfg(cvsver) < 1.3} {
  359.     cvserror "This function is not supported in CVS version $cvscfg(cvsver).
  360.  
  361. Please upgrade your CVS to version 1.3"
  362.     return
  363.   }
  364.  
  365.   if {! $incvs} {
  366.     cvs_notincvs
  367.     return 1
  368.   }
  369.  
  370.   if {$tagname == ""} {
  371.     cvserror "You must enter a tag name!"
  372.     return 1
  373.   }
  374.  
  375.   set cmd_options ""
  376.  
  377.   if {$cvscfg(cvsver) > 1.3} {
  378.     set cmd_options "$cmd_options -F"
  379.   }
  380.  
  381.   if {$args == "{}"} {
  382.     set filelist "."
  383.   } else {
  384.     set filelist $args
  385.   }
  386.  
  387.   if {$branch == "yes"} {
  388.     set cmd_options "$cmd_options -b"
  389.     catch {eval "exec $cvs tag $cmd_options $tagname $filelist"} tag_output
  390.     catch {eval "exec $cvs update -r $tagname $filelist"} tag_output2
  391.     set tag_output "$tag_output\n\n$tag_output2"
  392.   } else {
  393.     catch {eval "exec $cvs tag $cmd_options $tagname $filelist"} tag_output
  394.   }
  395.   view_output "CVS Tag" $tag_output
  396. }
  397.  
  398. proc cvs_update {tagname args} {
  399. #
  400. # This updates the files in the current directory.
  401. #
  402.   global cvs
  403.   global incvs
  404.  
  405.   if {! $incvs} {
  406.     cvs_notincvs
  407.     return 1
  408.   }
  409.  
  410.   if {$args == "{}"} {
  411.     set filelist "."
  412.   } else {
  413.     set filelist $args
  414.   }
  415.  
  416.   # changed the message to be a little more explicit.
  417.   # -sj
  418.   if { $filelist == "." } {
  419.       set mess "You are about to download from"
  420.       set mess "$mess the repository to your local"
  421.       set mess "$mess filespace ** ALL ** files which"
  422.       set mess "$mess have changed in it."
  423.   } else {
  424.       set mess "You are about to download from"
  425.       set mess "$mess the repository to your local"
  426.       set mess "$mess filespace these files which"
  427.       set mess "$mess have changed:\n"
  428.       regsub -all {" "} $filelist {"\\n\\t"} tmp
  429.       set mess "$mess\n$tmp"
  430.   }
  431.   set mess "$mess\n\nAre you sure?"
  432.   set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  433.  
  434.   if {$confirm == 0} {
  435.     # modified to allow putting the comandline executed to the console.
  436.     # more to support debugging than anything else.
  437.     # -sj
  438.     set str [join $filelist "" ]
  439.     if {$tagname == ""} {
  440.       set commandline "exec $cvs update $str "
  441.       catch {eval $commandline} view_this
  442.     } else {
  443.       set commandline "exec cvs update -r $tagname $str"
  444.       catch {eval $commandline} view_this
  445.     }
  446.     view_output "CVS Update" $view_this
  447.     setup_dir
  448.   }
  449. }
  450.  
  451. proc cvs_join {localfile branchver} {
  452. #
  453. # This does a join (merge) of the branchver revision of localfile to the
  454. # head revision.
  455. #
  456.   global cvs
  457.   global incvs
  458.  
  459.   if {! $incvs} {
  460.     cvs_notincvs
  461.     return 1
  462.   }
  463.  
  464.   set mess "This will merge revision $branchver to the head revision of $localfile
  465.  
  466. Are you sure?"
  467.   set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  468.  
  469.   if {$confirm == 0} {
  470.     catch {eval "exec $cvs update -j$branchver $localfile"} view_this
  471.     view_output "CVS Merge" $view_this
  472.     setup_dir
  473.   }
  474. }
  475.  
  476. proc cvs_delta {localfile ver1 ver2} {
  477. #
  478. # This merges the changes between ver1 and ver2 into the head revision.
  479. #
  480.   global cvs
  481.   global incvs
  482.  
  483.   if {! $incvs} {
  484.     cvs_notincvs
  485.     return 1
  486.   }
  487.  
  488.   if {$ver1 == {} || $ver2 == {}} {
  489.     cvserror "Must have two revision numbers for this function!"
  490.     return 1
  491.   }
  492.   set mess "This will merge the changes between revision $ver1 and $ver2 (if $ver1 > $ver2 the changes are removed) to the head revision of $localfile
  493.  
  494. Are you sure?"
  495.   set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  496.  
  497.   if {$confirm == 0} {
  498.     catch {eval "exec $cvs update -j$ver1 -j$ver2 $localfile"} view_this
  499.     view_output "CVS Merge" $view_this
  500.     setup_dir
  501.   }
  502. }
  503.  
  504. proc cvs_status args {
  505. #
  506. # This does a status report on the files in the current directory.
  507. #
  508.   global cvs
  509.   global incvs
  510.   global cvscfg
  511.  
  512.   # provided as convient place holders.
  513.   # -sj
  514.   set global_options ""
  515.   set cmd_options ""
  516.  
  517.   if {! $incvs} {
  518.     cvs_notincvs
  519.     return 1
  520.   }
  521.  
  522.   # added recurse capability to reports.
  523.   # -sj
  524.   # if recurse option is false or there are selected files, don't recurse
  525.   if { ( $cvscfg(recurse) == "false" ) || ( $args != {} ) } { 
  526.     set cmd_options "$cmd_options -l"
  527.   }
  528.  
  529.   if {$args == "{}"} {
  530.     set filelist "."
  531.   } else {
  532.     set filelist $args
  533.   }
  534.  
  535.   # Additional support added for 1.4
  536.   # -sj
  537.   if {$cvscfg(cvsver) < 1.3} {
  538.     set cmd_options ""
  539.     set cvscfg(rdetail) "verbose"
  540.   } elseif { $cvscfg(cvsver) < 1.4} {
  541.     set global_options "$global_options -q"
  542.   } else {
  543.     set global_options "$global_options -Q"
  544.   }
  545.   # added to support verious levels of verboseness. Ideas derived and some of the 
  546.   # awk expressions derived from GIC.
  547.   # -sj
  548.   if { $cvscfg(rdetail) == "verbose" } {
  549.       set commandline "exec $cvs $global_options status $cmd_options $filelist"
  550.   } elseif { $cvscfg(rdetail) == "summary" } {
  551.       set commandline "exec $cvs $global_options status $cmd_options $filelist | "
  552.       set commandline "$commandline awk {\$3 ~ /Status:/ "
  553.       set commandline "$commandline { printf(\"%s %s %s %s \\t%s\\n\", \$4, \$5, \$6, \$7, \$2);}}"
  554.   } elseif { $cvscfg(rdetail) == "terse" } {
  555.       set commandline "exec $cvs $global_options status $cmd_options $filelist | "
  556.       set commandline "$commandline awk {\$3 ~ /Status:/ {if (\$4 != \"Up-to-date\") "
  557.       set commandline "$commandline { printf(\"%s %s %s %s \\t%s\\n\", \$4, \$5, \$6, \$7, \$2);}}} "
  558.   }
  559.   # puts stderr "command line is $commandline"
  560.   catch { eval $commandline } view_this
  561.   if { $view_this == "" } {
  562.     set mess "Everything is Up-to-date."
  563.     set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK ]
  564.   } else {
  565.     view_output "CVS Status" $view_this
  566.   }
  567. }
  568.  
  569. proc cvs_check {} {
  570. #
  571. # This does a cvscheck on the files in the current directory.
  572. #
  573.   global cvs
  574.   global incvs
  575.   global cvscfg
  576.  
  577.   if {! $incvs} {
  578.     cvs_notincvs
  579.     return 1
  580.   }
  581.  
  582.   catch {exec cvscheck $cvscfg(checkrecursive)} view_this
  583.   view_output "CVS Check" $view_this
  584. }
  585.  
  586. proc cvs_checkout {mcode revision} {
  587. #
  588. # This checks out a new module into the current directory.
  589. #
  590.   #puts "Entered cvs_checkout, mcode=$mcode, revision=$revision"
  591.   global cvs
  592.   global incvs
  593.  
  594.   if {$incvs} {
  595.     set mess "You are already in a CVS controlled directory.  Are you"
  596.     set mess "$mess sure that you want to check out another module in"
  597.     set mess "$mess to this directory?"
  598.     set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  599.     if {$confirm} { return 1 }
  600.   }
  601.  
  602.   set mess "This will check out $mcode from CVS.\nAre you sure?"
  603.   set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  604.   #puts "From cvs_checkout, mcode=$mcode  pwd=[exec pwd]"
  605.   if {$confirm == 0} {
  606.     feedback_cvs "Checking out module $mcode, please wait"
  607.     if {$revision == {}} {
  608.       catch {exec $cvs co $mcode} view_this
  609.     } else {
  610.       catch {exec $cvs co -r $revision $mcode} view_this
  611.     }
  612.     feedback_cvs ""
  613.     view_output "CVS Checkout" $view_this
  614.     setup_dir
  615.   }
  616. }
  617.  
  618. proc cvs_filelog {mcode filename} {
  619. #
  620. # This looks at a revision log of a file from the repository without
  621. # checking it out.
  622. #
  623.   global cvs
  624.   global cvsroot
  625.   global location
  626.   global cvscfg
  627.   
  628.   feedback_cvs "Executing rlog command, please wait"
  629.   catch {exec rlog $cvsroot/$location($mcode)/$filename} view_this
  630.   feedback_cvs ""
  631.  
  632.   # Old style file log with just the output from cvs log.
  633.   # view_output "CVS File Log" $view_this
  634.  
  635.   # New style file log viewer
  636.   new_logcanvas "no file" $view_this
  637. }
  638.  
  639. proc rcs_fileview {filename revision} {
  640. #
  641. # This views an RCS file in the repository.
  642. #
  643.   if {$cvscfg(remote)} {
  644.     cvs_remote_bad
  645.     return 1
  646.   }
  647.  
  648.   if {$revision == {}} {
  649.     catch {exec co -p $filename 2>/dev/null} view_this
  650.   } else {
  651.     catch {exec co -p$revision $filename 2>/dev/null} view_this
  652.   }
  653.   view_output "CVS File View" $view_this
  654. }
  655.  
  656. proc cvs_fileview {mcode filename revision} {
  657. #
  658. # This looks at a revision of a file from the repository without
  659. # checking it out.
  660. #
  661.   global cvs
  662.  
  663.   if {$revision == {}} {
  664.     catch {exec $cvs co -p $mcode/$filename 2>/dev/null} view_this
  665.   } else {
  666.     catch {exec $cvs co -p -r $revision $mcode/$filename 2>/dev/null} view_this
  667.   }
  668.   view_output "CVS File View" $view_this
  669. }
  670.  
  671. proc rcs_filediff {filename ver1 ver2} {
  672. #
  673. # This does a diff of an RCS file within the repository.
  674. #
  675.   if {$cvscfg(remote)} {
  676.     cvs_remote_bad
  677.     return 1
  678.   }
  679.   if {$ver1 == {} || $ver2 == {}} {
  680.     cvserror "Must have two revision numbers for this function!"
  681.     return 1
  682.   }
  683.   # catch {exec rcsdiff -r$ver1 -r$ver2 $filename} view_this
  684.   # view_output "CVS File Diff" $view_this
  685.   exec tkdiff -r$ver1 -r$ver2 $filename &
  686. }
  687.  
  688.  
  689. proc cvs_filediff {mcode filename ver1 ver2} {
  690. #
  691. # This looks at a diff of a file from the repository without
  692. # checking it out.
  693. #
  694.   global cvs
  695.   global cvsroot
  696.   global location
  697.  
  698.   rcs_filediff $cvsroot/$location($mcode)/$filename $ver1 $ver2
  699. }
  700.  
  701. proc cvs_export {mcode revision} {
  702. #
  703. # This exports a new module (see man cvs and read about export) into
  704. # the current directory.
  705. #
  706.   global cvs
  707.   global incvs
  708.   global cvscfg
  709.  
  710.   if {$incvs} {
  711.     cvs_incvs
  712.     return 1
  713.   }
  714.  
  715.   if {$cvscfg(cvsver) < 1.3} {
  716.     cvserror "This function is not supported in CVS version $cvscfg(cvsver).
  717.  
  718. Please upgrade your CVS to version 1.3"
  719.     return
  720.   }
  721.  
  722.   if {$revision == {}} {
  723.     cvserror "You must enter a tag name for this function."
  724.     return
  725.   }
  726.  
  727.   set mess "This will export $mcode from CVS.\nAre you sure?"
  728.   set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  729.  
  730.   if {$confirm == 0} {
  731.     catch {exec $cvs export -r $revision $mcode} view_this
  732.     view_output "CVS Export" $view_this
  733.     setup_dir
  734.   }
  735. }
  736.  
  737. proc cvs_patch {mcode revision1 revision2} {
  738. #
  739. # This creates a patch file between two revisions of a module.  If the
  740. # second revision is null, it creates a patch to the head revision.
  741. #
  742.   global cvs
  743.   global cvscfg
  744.  
  745.   if {$revision1 == {}} {
  746.     cvserror "You must enter a tag name for this function."
  747.     return
  748.   }
  749.  
  750.   set mess "This will make a patch file for $mcode from CVS.\nAre you sure?"
  751.   set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  752.  
  753.   if {$confirm == 0} {
  754.     if {$revision2 == {}} {
  755.       catch {exec $cvs patch -r $revision1 $mcode > $mcode.pat} view_this
  756.     } else {
  757.       catch {exec $cvs patch -r $revision1 -r $revision2 $mcode > $mcode.pat} \
  758.         view_this
  759.     }
  760.     set view_this "$view_this\n\nPatch file $mcode.pat created."
  761.     view_output "CVS Patch" $view_this
  762.     setup_dir
  763.   }
  764. }
  765.  
  766. proc cvs_patch_summary {mcode revision1 revision2} {
  767. #
  768. # This creates a patch summary of a module between 2 revisions.
  769. #
  770.   global cvs
  771.   global cvscfg
  772.  
  773.   if {$revision1 == {}} {
  774.     cvserror "You must enter a tag name for this function."
  775.     return
  776.   }
  777.  
  778.   if {$revision2 == {}} {
  779.     catch {exec $cvs patch -s -r $revision1 $mcode} view_this
  780.   } else {
  781.     catch {exec $cvs patch -s -r $revision1 -r $revision2 $mcode} view_this
  782.   }
  783.   view_output "CVS Patch Summary" $view_this
  784. }
  785.  
  786. proc cvs_version {} {
  787. #
  788. # This shows the current CVS version number.
  789. #
  790.   global cvs
  791.  
  792.   catch {exec $cvs -v} view_this
  793.   view_output "CVS Version" $view_this
  794. }
  795.  
  796. proc cvs_rtag {mcode branch tagnameA tagnameB} {
  797. #
  798. # This tags a module in the repository.
  799. #
  800.   global cvs
  801.   global cvscfg
  802.  
  803.   if {$cvscfg(cvsver) < 1.3} {
  804.     set command "tag"
  805.   } else {
  806.     set command "rtag"
  807.   }
  808.  
  809.   set cmd_options ""
  810.  
  811.   if {$branch == "yes"} {
  812.     if {$cvscfg(cvsver) < 1.3} {
  813.       set mess "This function is not supported in CVS version $cvscfg(cvsver)."
  814.       set mess "$mess\n\nPlease upgrade your CVS to version 1.3"
  815.       cvserror $mess
  816.       return
  817.     }
  818.     set cmd_options "-b"
  819.   }
  820.  
  821.   # puts stderr "Using options for CVS version $cvscfg(cvsver)"
  822.   if {$cvscfg(cvsver) > 1.3} {
  823.     set cmd_options "$cmd_options -F"
  824.   }
  825.  
  826.   if {$tagnameA == ""} {
  827.     cvserror "You must enter a tag name!"
  828.     return 1
  829.   }
  830.  
  831.   set mess "This will tag module \"$mcode\" in CVS with tag \"$tagnameA\"."
  832.   if {$tagnameB == ""} {
  833.     set mess "$mess\n\nThe head revision of all files will be tagged."
  834.   } else {
  835.     set mess "$mess\n\nThe revisions tagged with \"$tagnameB\" will be tagged."
  836.     set cmd_options "$cmd_options -r $tagnameB"
  837.   }
  838.   set mess "$mess\n\nAre you sure?"
  839.   set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  840.  
  841.   if {$confirm == 0} {
  842.     catch {eval "exec $cvs $command $cmd_options $tagnameA $mcode"} view_this
  843.     view_output "CVS Rtag" $view_this
  844.   }
  845. }
  846.  
  847. proc cvs_usercmd {args} {
  848. #
  849. # Allows the user to run a user-specified cvs command.
  850. #
  851.   global cvs
  852.  
  853.   catch {eval "exec $cvs $args"} view_this
  854.   view_output "CVS [lindex $args 0]" $view_this
  855. }
  856.  
  857. proc cvs_anycmd {args} {
  858. #
  859. # Allows the user to run any user-specified command.
  860. #
  861.   catch {eval "exec $args"} view_this
  862.   view_output [lindex $args 0] $view_this
  863. }
  864.  
  865. proc view_output {title output_string} {
  866. #
  867. # Set up a dialog containing a text box that can be used to view
  868. # the report on the screen.
  869. #
  870.   static {viewer 0}
  871.  
  872.   # If nothing to report, then say so.
  873.   # -sj
  874.   if {$output_string == ""} {
  875.     set mess "Nothing to report."
  876.     set confirm [tk_dialog .message {Confirm!} $mess warning 0 OK Quit]
  877.   } else {
  878.     incr viewer
  879.     set cvsview ".cvsview$viewer"
  880.     toplevel $cvsview
  881.     text $cvsview.text -setgrid yes -relief sunken -border 2 \
  882.       -yscroll "$cvsview.scroll set"
  883.     scrollbar $cvsview.scroll -relief sunken \
  884.       -command "$cvsview.text yview"
  885.     button $cvsview.ok -text "OK" \
  886.       -command "destroy $cvsview"
  887.  
  888.     pack $cvsview.ok -side bottom -fill x
  889.     pack $cvsview.scroll -side right -fill y -padx 2 -pady 2
  890.     pack $cvsview.text -fill both -expand 1
  891.  
  892.     wm title $cvsview "$title Output"
  893.     $cvsview.text insert end $output_string
  894.     $cvsview.text configure -state disabled
  895.   }
  896. }
  897.